<template lang="pug">
modal(name="printOrder", width="100%", height="100%" @before-open="beforeOpen")
  .print(ref="print")
    .el-icon-close(@click="close" v-show="!isPrint")
    .print-title(v-show="!isPrint") 订单信息
    .print-body(ref="content")
      table(cellspacing="0" border="1" style=" border:1px solid #ddd")
        tr
          th 寄货方
          th 订单详情
        tr
          td(style="width: 50%")
            .table-item.label-weight {{order.saler.company}}
            .table-item {{order.saler.address}}
            .table-item
              .table-item-label 电话：
              .table-item-value {{order.saler.mobile}}
            .table-item
              .table-item-label E-Mail：
              .table-item-value {{order.saler.email}}
            //- .table-item
              .table-item-label 网址：
              .table-item-value
          td(style="width: 50%")
            .table-item
              .table-item-label 下单日期：
              .table-item-value {{new Date(order.create_time * 1000).format('yyyy-MM-dd hh:mm:ss')}}
            .table-item
              .table-item-label 订单号：
              .table-item-value {{order.order_sn}}
            .table-item
              .table-item-label 支付方式：
              .table-item-value {{order.pay_type}}
            .table-item
              .table-item-label 用户备注：
              .table-item-value {{order.user_note}}
      table(cellspacing="0" border="1" style=" border:1px solid #ddd")
        tr
          th(colspan="2") 收货信息(发货前务必与运营商确认收货地址)
        tr
          td(style="width: 50%")
            .table-item-title 运营商收货信息
            .table-item
              .table-item-label 收货人：
              .table-item-value {{order.dt_address.consignee}}
            .table-item
              .table-item-label 联系方式：
              .table-item-value {{order.dt_address.mobile}}
            .table-item
              .table-item-label 收货地址：
              .table-item-value {{order.dt_address.area}}{{order.dt_address.address}}
            .table-item
              .table-item-label 建议物流：
              .table-item-value {{order.dt_address.need_shipping}}
          td(style="width: 50%")
            .table-item-title 消费者信息
            .table-item
              .table-item-label 收货人：
              .table-item-value {{order.buy_address.consignee}}
            .table-item
              .table-item-label 联系方式：
              .table-item-value {{order.buy_address.mobile}}
            .table-item
              .table-item-label 收货地址：
              .table-item-value {{order.buy_address.area}}{{order.buy_address.address}}
      table(cellspacing="0" border="1"  style=" border:1px solid #ddd")
        tr
          th(colspan="2") 供应商实际发送物流
        tr
          td(style="width: 40%") 物流公司
          td(style="width: 60%") 物流单号
        tr
          td {{order.actual_shipping.shipping_name}}
          td {{order.actual_shipping.delivery_sn}}
      table(cellspacing="0" border="1"  style=" border:1px solid #ddd")
        tr
          th 商品名称
          th 状态
          th 规格属性
          th 数量
        tr(v-for="item, index in order.goods")
          td(style="width: 32%") {{item.goods_name}}
          td {{order.order_status}}
          td(style="width: 35%") {{item.spec_key_name}}
          td {{item.goods_num}}
      .table-item-button(v-show="!isPrint")
        el-button(size="mini", @click="print") 打印
</template>

<script>
export default {
  name: 'printOrder',
  data () {
    return {
      order: {
        actual_shipping: {
          shipping_name: '',
          shipping_mobile: '',
          delivery_sn: '',
          send_num: '',
          arrival_time: ''
        },
        buy_address: {
          consignee: '',
          mobile: '',
          area: '',
          address: ''
        },
        dt_address: {
          consignee: '',
          mobile: '',
          area: '',
          need_shipping: '',
          address: ''
        },
        saler: {
          company: '',
          address: '',
          mobile: '',
          email: ''
        }
      },
      isPrint: false
    }
  },
  methods: {
    close () {
      this.$modal.hide('printOrder')
    },
    print () {
      this.isPrint = true
      this.$nextTick(() => {
        let newdoc = this.$refs.print
        let newContent = newdoc.innerHTML
        let oldContent = document.body.innerHTML
        document.body.innerHTML = newContent
        let html = document.getElementsByTagName('html')[0]
        html.style.overflow = 'unset'
        window.print()
        window.location.reload()
        document.body.innerHTML = oldContent
        this.isPrint = false
      })
    },
    async beforeOpen ({ params }) {
      this.order = params.order
    }
  }
}
</script>
<style lang="scss" scoped>
.print {
  height: 100%;
  width: 100%;
  padding-top: 60px;
  background: #fff;
  z-index: 9999!important;
  position: relative;
  overflow-y: auto;
}
.el-icon-close {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 40px;
  cursor: pointer;
}
.print-title {
  font-size: 36px;
  color: #333333;
  text-align: center;
}
.print-body {
  font-size: 14px;
  color: #333;
  width: 1140px;
  margin: 0 auto;
}
.print-body table {
  width: 100%;
  margin-top: 30px;
}
.print-body table th,
.print-body table td {
  padding: 12px;
}
.print-body .table-item {
  display: flex;
  align-items: center;
  line-height: 20px;
}
.print-body .table-item .table-item-label,
.label-weight {
  font-weight: 600;
}
.table-item-button {
  text-align: center;
  border: 1px solid rgb(221, 221, 221);
  border-top: none;
  height: 52px;
  line-height: 52px;
}
</style>
